package com.shenzw.mybatisdemo.repository;

import com.shenzw.mybatisdemo.controller.response.DeptResponseMore;
import com.shenzw.mybatisdemo.controller.response.EmployeeResponseOne;
import com.shenzw.mybatisdemo.domain.Dept;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

/**
 * @author shenzw
 * @date 2023/11/30
 */
@Mapper
public interface DeptRepository {

    /**
     * 获取部门信息（包含员工信息）：一对多写法 ①
     *
     * @param deptId 部门id
     * @return List<DeptResponse>
     */
    List<DeptResponseMore> getDeptInfo(@Param("deptId") Integer deptId);

    /**
     * 获取部门信息（包含员工信息）：一对多写法 ②
     *
     * @param deptId 部门id
     * @return List<DeptResponse>
     */
    List<DeptResponseMore> getDeptInfo2(@Param("deptId") Integer deptId);

    /**
     * 获取员工信息：一对一写法
     *
     * @param id 员工id
     * @return List<EmployeeResponseOne>
     */
    List<EmployeeResponseOne> getEmploy(@Param("id") Integer id);

    List<Dept> selectDeptByName(@Param("deptName") String deptName);

    @Select(value = "select id, dept_name, dept_desc from dept where dept_name = #{deptName}")
    List<Dept> selectDeptByName2(@Param("deptName") String deptName);

    @Select(value = "select id, dept_name, dept_desc from dept where id = #{id}")
    Optional<Dept> selectDeptById(@Param("id") Integer id);
}
